<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * Copyright (C) 2007  Robert Moss
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

class Country extends JLClass{
  
  var $countries_id;
  var $countries_name;
  var $countries_localname;
  var $countries_iso_code_2;
  var $countries_iso_code_3;
  var $countries_iso_official;
  var $published;
  var $checked_out;
  var $checked_out_time;
  
  function Country( &$db ) {
		$this->mosDBTable( '#__joomleague_countries', 'countries_id', $db );
	}
    function publish_array( $cid=null, $post=null, $publish=1, $myid=0 ) {
		if (!is_array( $cid ) || count( $cid ) < 1) {
			$this->_error = "No items selected.";
			return false;
		}
		
		$cids = implode( ',', $cid );
		
		$this->_db->setQuery( "UPDATE $this->_tbl SET published='$publish'"
		. "\nWHERE countries_id IN ($cids) AND (checked_out=0 OR (checked_out='$myid'))"
		);
    print $this->_db->getQuery();
		if (!$this->_db->query()) {
			$this->_error = $this->_db->getErrorMsg();
			return false;
		}
		
		if (count( $cid ) == 1) {
			$this->checkin( $cid[0] );
		}
		$this->_error = '';
		return $post["countries_id"];
	}
	function getFlag() {
	  global $mosConfig_absolute_path, $mosConfig_live_site, $country;
	  if (file_exists($mosConfig_absolute_path."/images/joomleague/flags/".strtolower($this->countries_iso_code_2).".png")) {
      return "<img src=\"".$mosConfig_live_site."/images/joomleague/flags/".strtolower($this->countries_iso_code_2).".png\" alt=\"".$country[$this->countries_iso_code_3]."\" title=\"".$country[$this->countries_iso_code_3]."\" hspace=\"2\" /> ";
    }
    else return " [".$this->countries_iso_code_3."]";
	}
	 
}

?>
